<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>hello Raphael</title>
<script src="http://libs.baidu.com/mootools/1.4.5/mootools-yui-compressed.js"></script>
<script src="../../scripts/raphael.js"></script>
<script src="../../scripts/FormUtil.js" charset="utf-8"></script>
<script src="map.js"></script>

<script>
var paper;
var w = 800;
var h = 600;
function test1(){
	//var paper = Raphael(10, 50, 320, 240);//在浏览器窗口中，坐标 (10,50) 位置创建一个 canvas 对象，长320px，宽240px。
	paper=Raphael("raphael1",800,600);//在 id 为 raphael1 元素中创建画布
	// 规则的矩形
	var c1 = paper.rect(0, 0, w, h);
	c1.attr({"fill":"#c0c0c0"}); //attr 方法用于设定对象属性
	// 带圆角的矩形
	var c2 = paper.rect(10, 10, w-20, h-20, 10);

	var text=paper.text(150,200,"Hello from 陈三");
	text.attr({"font-size":"30px","fill":"blue","stroke":"red","opacity":".5"});
	
	var rect=paper.rect(150,150,150,150,5);
	rect.attr({"stroke-dasharray":"-"});
	rect.transform("t100,100r45t-100,0s.5");

	var circle=paper.circle(100,260,50);
	circle.attr({"fill":"red"}); //attr 方法用于设定对象属性

	// 动画
	//circle.animate({cx: 10, cy: 20, r: 8, "fill": "blue"}, 10e3);
	
	// 事件
	circle.click(function(e){
		circle.remove();
	});
	circle.hover(function(){circle.attr({"fill":"green"});},function(){circle.attr({"fill":"red"});});//给 circle 对象绑定 hover 事件
	
	//path
	var path1 = paper.path("M153 334 C153 334 151 334 151 334 C151 339 153 344 156 344 C164 344 171 339 171 334 C171 322 164 314 156 314 C142 314 131 322 131 334 C131 350 142 364 156 364 C175 364 191 350 191 334 C191 311 175 294 156 294 C131 294 111 311 111 334 C111 361 131 384 156 384 C186 384 211 361 211 334 C211 300 186 274 156 274 ");
	
	var path2 = paper.path("M16,1.466C7.973,1.466,1.466,7.973,1.466,16c0,8.027,6.507,14.534,14.534,14.534c8.027,0,14.534-6.507,14.534-14.534C30.534,7.973,24.027,1.466,16,1.466zM16,29.534C8.539,29.534,2.466,23.462,2.466,16C2.466,8.539,8.539,2.466,16,2.466c7.462,0,13.535,6.072,13.535,13.533C29.534,23.462,23.462,29.534,16,29.534zM11.104,14c0.932,0,1.688-1.483,1.688-3.312s-0.755-3.312-1.688-3.312s-1.688,1.483-1.688,3.312S10.172,14,11.104,14zM20.729,14c0.934,0,1.688-1.483,1.688-3.312s-0.756-3.312-1.688-3.312c-0.932,0-1.688,1.483-1.688,3.312S19.798,14,20.729,14zM8.143,21.189C10.458,24.243,13.148,26,16.021,26c2.969,0,5.745-1.868,8.11-5.109c-2.515,1.754-5.292,2.734-8.215,2.734C13.164,23.625,10.54,22.756,8.143,21.189z");
	path2.click(function(e){
		path2.attr("path", "M250 150 L150 350 L350 350 Z");
		path2.attr({"fill":"#090"});
	});

	var imgPath = "http://static.oschina.net/uploads/user/61/122189_50.jpg?t=1";
	var img = paper.image(imgPath, 300, 100, 80, 80);
	//for(var i=0;i<5000;i++)
	//var img = paper.image(imgPath, 90*(i%15), 6*i, 80, 80);
	
	
}

function zoom(){
	paper.setViewBox(0, 0, w-=20, h-=20, true);
	//paper.setSize(w/2, h/2);
}

var area;

function init(){
	area = new HallArea('area1', 800, 600);

	var jsonArray = [{x:0,y:0},{x:0,y:1*20},{x:0,y:2*20}];
	for(var i=0;i<jsonArray.length;i++){
		var json = jsonArray[i];
		var sofa = new Sofa(area, json);
		sofa.repaint();
		sofa.click(_onItemClick);
	}
}

var _onItemClick = function(e2, e ){
	alert(e2.value.y);
	for(name in e){
		//alert(name+'='+e[name]);
	}
}

function add(){
	var properties = {x:0, y:20*area.itemList.length};
	var sofa = new Sofa(area, properties);
	sofa.repaint();
	sofa.click(_onItemClick);
}

function zoom2(){
	area.zoom(-50);
}

function del(){
	area.itemList.pop().dispose();
}

function onDivMousemove(e){
	//alert(e.x+','+e.y+'|'+e.srcElement.outerHTML);
}
</script>

</head>

<body>
	<button onclick="test1()">test1</button>
	<button onclick="zoom()">zoom</button>
	<span>&nbsp;|&nbsp;</span>
	<button onclick="init()">init</button>
	<button onclick="add()">add</button>
	<button onclick="del()">del</button>
	<button onclick="zoom2()">zoom2</button>
	<div id="raphael1" style="background-color: #9999FF;" onmousemove="onDivMousemove(event)"></div>
	<div id="area1" style="background-color: #ddd;" onselectstart="return false"></div>
</body>
</html>
